package com.comleader.operator.controller;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.comleader.operator.pojo.entity.InspectRecordEntity;
import com.comleader.operator.pojo.entity.InspectReportEntity;
import com.comleader.operator.pojo.param.InspectRecordParam;
import com.comleader.operator.pojo.param.InspectReportParam;
import com.comleader.operator.service.InspectRecordService;
import com.comleader.operator.service.InspectReportService;
import com.mybatisflex.core.paginate.Page;

/**
 * 检查记录表 控制层。
 * 
 * @menu 检查记录
 * @author 连新景
 * @since 1.0
 */
@Validated
@RestController
@RequestMapping("/inspectRecord")
public class InspectRecordController {

    @Resource
    private InspectRecordService inspectRecordService;
    @Resource
    private InspectReportService inspectReportService;

    /**
     * 分页查询检查记录
     *
     * @param param 分页对象
     * @return 分页对象
     */
    @GetMapping("/page")
    public Page<InspectRecordEntity> page(@Valid InspectRecordParam param) {
        return inspectRecordService.selectPage(param);
    }

    /**
     * 查看检查报告
     *
     * @param id inspectRecord主键
     * @return 检查记录表详情
     */
    @GetMapping("/viewReport/{id}")
    public List<InspectReportEntity> viewReport(@PathVariable @NotNull(message = "检查记录id不能为空") Integer id) {
        return inspectReportService.listByRecordId(id);
    }

    /**
     * 下载
     *
     * @param param
     */
    @PostMapping("/download")
    public void download(@RequestBody @Valid InspectReportParam param, HttpServletResponse response) throws IOException {
        inspectRecordService.download(param, response);
    }

    /**
     * 刪除
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("/remove/{id}")
    public void remove(@PathVariable @NotNull(message = "id不能为空") Integer id) {
        inspectReportService.delete(id);
    }

}